<?php

/**
 * \file
 * Classe `SuggestBox`.
 */

namespace pilar\AdvancedFormMembers /* \cond */ ; /* \endcond */
{

// Utilisation de la librairie javascript d'autocompletion
 global $pJS, $pCSS;
 $pJS[] = '/js/jquery-autocomplete/jquery.autocomplete.min.js';
 $pCSS[] = '/js/jquery-autocomplete/jquery.autocomplete.css';

/**
 * Membre SuggestBox
 *
 * \since 11/02/2009
 * \author Olivier LEMASLE <o.lemasle@gmail.com>
 *
 */
 
final class SuggestBox extends \pilar\SimpleFormMembers\TextBox {

protected function loadDefaultParams() {
 parent::loadDefaultParams();
 
 $this->params->set(array(
  'size' => 26,
  'maxLength' => 255
 ));
 
 $this->params->define(array(
  'entity' => '',
  'member' => ''
 ));
}

protected function outputGuiController() {
 global $APPS;
 $elements = $this->get('entity')->newCollection();
 parent::outputGuiController();
?>
$('#<?php echo $this->globalId() ?>').val('<?php echo $this->value() ?>');
var data = [<?php foreach($elements as $item) {
echo "'".$item->__get($this->get('member'))->get()."', ";
} ?>
''];
$('#<?php echo $this->globalId() ?>').autocomplete(data, {
    minChars: 0,
    matchContains: true,
    autoFill: false
});
<?php
}

} // Class.

} // Namespace.
?>